/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package io;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.Scanner;

/**
 *
 * @author saltcoffee
 */
public class ReadWriteFile_video {
    public static void main (String [] args){
		try {
                        String a;
                        Scanner input=new Scanner(System.in);
                        System.out.println("Moi ban nhap vao ten file: ");
                        a=input.nextLine();
			FileInputStream fin = new FileInputStream(a);
			Reader r= new InputStreamReader(fin, "UTF8");
                    StringBuilder text;
                    Writer out;
                    try (BufferedReader br = new BufferedReader(r)) {
                        text = new StringBuilder();
                        String line;
                        String b;
                        System.out.println("Nhap ten file dau ra: ");
                        b=input.nextLine();
                        FileOutputStream fout = new FileOutputStream(b);
                        out = new OutputStreamWriter(fout,"UTF8");
                        while ((line = br.readLine())!= null){
                                text.append(line).append("\n");
                                
                        }
                    }
			
			String t=text.toString();
			System.out.println(t);
			out.write(t);
			
			out.close();
		}
		
		catch (Exception e) {
			}
}
}
